cmake_minimum_required(VERSION 2.8)
project(PBACeres)

option(DataIO "ON for compile or OFF for not" ON)

SET(CMAKE_BUILD_TYPE Release ) # change into Release if u don't want to
option (BUILD_TESTS "Builds all gtests" ON)
MESSAGE("Build type: " ${CMAKE_BUILD_TYPE})

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}     -Wall -O3  -march=native")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3  -march=native")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
add_definitions(-std=c++11)

include(ExternalProject)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

# option (BUILD_TESTS
#         "Builds all gtests" ON) 

# add eigen 
find_package(Eigen 3.2.10 REQUIRED)
message("--Found Eigen library in ${EIGEN_INCLUDE_DIR}")
include_directories(${EIGEN_INCLUDE_DIR})


# DataIO module
include_directories(${PROJECT_SOURCE_DIR}/DataIO/include/)
add_subdirectory(DataIO)
# add_dependencies(DataIO ${Boost_LIBRARIES})

# PBA core module
include_directories(${PROJECT_SOURCE_DIR}/PBACore/include/)
add_subdirectory(PBACore)

# initialization module
include_directories(${PROJECT_SOURCE_DIR}/initialization/include)

# util module
include_directories(${PROJECT_SOURCE_DIR}/util)

# Viewer module
include_directories(${PROJRCT_SOURCE_DIR}/Viewer)

# DataStructure module
include_directories(${PROJRCT_SOURCE_DIR}/DataStructure)

add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} DataIO PBACore)

## add gtest support

if(${BUILD_TESTS})
enable_testing()
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})
endif()

## set test projects' name
# set(PROJECT_TEST_NAME ${PROJECT_NAME}_test)
# add_executable(${PROJECT_TEST_NAME} test/test_main.cpp
#                                     test/test_jacobian3.cpp
#                                     test/test_jacobian4.cpp
#                                     test/test_gradient.cpp)

# ## gtest need pthread to run in parallel testing
# target_link_libraries(${PROJECT_TEST_NAME}  ${GTEST_LIBRARY} 
#                                             ${GMOCK_LIBRARY} 
#                                             PBACeresLib 
#                                             ${CERES_LIBRARIES}
#                                             pthread)
# add_test(test ${PROJECT_TEST_NAME})

